
-- $Id: FyLooter.lua 73 2009-04-06 14:21:13Z Fylgjas $

-- ========================================================================= --
-- Copyright © 2009 Thomas ROBERT (aka Fylgjas EU - Marécage de Zangar)      --
-- ========================================================================= --
-- This file is part of FyLooter.                                            --
--                                                                           --
-- FyLooter is free software: you can redistribute it and/or modify it under --
-- the terms of the GNU General Public License as published by the Free      --
-- Software Foundation, either version 3 of the License, or (at your option) --
-- any later version.                                                        --
--                                                                           --
-- FyLooter is distributed in the hope that it will be useful, but WITHOUT   --
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     --
-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for  --
-- more details.                                                             --
--                                                                           --
-- You should have received a copy of the GNU General Public License along   --
-- with FyLooter. If not, see <http://www.gnu.org/licenses/>.                --
-- ========================================================================= --

FyLooter = LibStub("AceAddon-3.0"):NewAddon("FyLooter", "AceConsole-3.0",
                                                        "AceEvent-3.0",
                                                        "AceComm-3.0",
                                                        "AceSerializer-3.0");

-- ========================================================================= --

FyLooter.revision = tonumber(string.sub("$Rev: 73 $", 7, -3));

-- ========================================================================= --

FyLooter.DEBUG = true;
FyLooter.ADMIN = true;

FyLooter.Status = {
  NEED  = 1,
  GREED = 2,
  PASS  = 3,
};

-- ========================================================================= --

local defaults = {
  ["char"] = {
    ["settings"] = {
      ["mb_x"] = 0,
      ["mb_y"] = -80,
      ["backdrop"] = {
        ["bgFile"] = "Interface\\Tooltips\\ChatBubble-Background",
        ["tile"] = true,
        ["tileSize"] = 16,
        ["edgeFile"] = "Interface\\Tooltips\\UI-Tooltip-Border",
        ["edgeSize"] = 16,
        ["insets"] = {
          ["left"] = 3,
          ["right"] = 3,
          ["top"] = 3,
          ["bottom"] = 3,
        },
      },
    },
    ["timestamp"] = 0,
    ["players"] = {},
  }
};

-- ========================================================================= --

-- 
-- FyLooter:OnInitialize
--
function FyLooter:OnInitialize()
  local db = LibStub("AceDB-3.0"):New("FyLooter_DB_test", defaults);
  FyLooter.db = db.char;
--[[
  self.settings   = db.char.settings;
  self.timestamp  = db.char.timestamp;
  self.players    = db.char.players;
--]]
  self.candidates = {};
  self.pending = false;
  self.deprecated = false;

  self.versions = {};
  self.versions[UnitName("player")] = self.revision;

  self:SetupFrames();
  self:SetupMinimapButton()
end

-- 
-- FyLooter:OnEnable
-- 
function FyLooter:OnEnable()
  self:RegisterEvent("OPEN_MASTER_LOOT_LIST", self.OnMasterLootListOpened);
  self:RegisterComm("FyLooter_Comm", self.OnComm);

  self:CheckVersion();
  self:Checkout();
end

-- 
-- FyLooter:OnDisable
--
function FyLooter:OnDisable()
  self:UnregisterAllEvents();
  self:UnregisterAllComm();
end

-- ========================================================================= --

-- 
-- FyLooter:Delete
--
function FyLooter:Delete(object)
  if (object) then
    if (type(object) == "table") then
      for k in pairs(object) do
	    	self:Delete(object[k]);
      end
    end

    object = nil;
  end
end

-- 
-- FyLooter:Clone
--
function FyLooter:Clone(object)
  local clone = nil;

  if (type(object) == "table") then
    clone = {};
    for k, v in pairs(object) do
      clone[FyLooter:Clone(k)] = FyLooter:Clone(v);
    end
  else
    clone = object;
  end

  return clone;
end

-- 
-- FyLooter:Debug
--
function FyLooter:Debug(msg)
	if (FyLooter.DEBUG == true) then
		DEFAULT_CHAT_FRAME:AddMessage("DEBUG - FyLooter: " .. msg, 0.8, 0.5, 0.2);
	end
end

-- ========================================================================= --


